import { Text } from "./text";

export enum ScoreOperations {
  INCREASE = 0,
  DECREASE = 1, //减少
  SET_VALUE = 2,
}

export class Score extends Text{
  private scoreValue: number;

  constructor(scene: Phaser.Scene, x: number, y: number, initScore = 0) {
    console.log('self=score,ts', scene, x, y, initScore = 0)
    super(scene, x, y, `z289得分：${initScore}`);

    scene.add.existing(this); //用于将当前对象添加到指定场景的方法，这意味着该对象将被纳入场景的更新和渲染循环中。

    this.scoreValue = initScore
  }

  public changeValue(operation:ScoreOperations, value:number): void {
    console.log('changeValue-值改变没', operation, value)
    switch (operation) {
      case ScoreOperations.INCREASE:
        this.scoreValue += value;
        break
      case ScoreOperations.DECREASE:
        this.scoreValue -= value;
        break
      case ScoreOperations.SET_VALUE:
        this.scoreValue = value
        break;
      default:
        break;
    }

    this.setText(`z23得分：${this.scoreValue}`)
  }

  public getValue():number {
    return this.scoreValue;
  }
}
